#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "common.h"
#include "drawwindow.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    std::map<QString, QString>* getTableData();
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
public slots:
    void enableOrDiasbleIdcExport(int state)
    {
        QPushButton* exportPathBrowse = this->findChild<QPushButton*>("IDC_EXPORT_PATH_BROWSE");
        QComboBox* exportPath  = this->findChild<QComboBox*>("IDC_EXPORT_PATH");
        if (exportPath == NULL || exportPathBrowse == NULL) return;
        if(state == Qt::Checked)
        {
            //tableData->insert(std::make_pair("IDC_IS_EXPORT", "1"));
            tableData->find("IDC_IS_EXPORT")->second = "1";
            exportPath->setEnabled(true);
            exportPathBrowse->setEnabled(true);
        }
        else
        {
            //tableData->insert(std::make_pair("IDC_IS_EXPORT", "0"));
            tableData->find("IDC_IS_EXPORT")->second = "0";
            exportPath->setEnabled(false);
            exportPathBrowse->setEnabled(false);
        }
    }
    void configExportFilePath()
    {
        QFileDialog* fileDialog = new QFileDialog();
        QString filePath = fileDialog->getSaveFileName(nullptr,"保存路径","untitled.dwg","dwg文件(*.dwg)");
        if(filePath.length() > 0)
        {
            QComboBox* exportPath  = this->findChild<QComboBox*>("IDC_EXPORT_PATH");
            //this->tableData->insert(std::make_pair("IDC_EXPORT_PATH",filePath));
            this->tableData->find("IDC_EXPORT_PATH")->second = filePath;
            exportPath->setEditText(filePath);
        }
    }
    void switchWindowType(int idx)
    {
        qDebug() << idx;
        if(idx >= 0 && idx <=2)
        {
                    changeWnd(idx);
        }
    }
    void drawPreviewGraphic()
    {
        drawCADGraphic();
    }
    void exportFile()
    {
        drawCADGraphic();
    }

private:
    void initComponment();
    void initEnvironment();
    void findAndConnect();
    bool checkText();
    void changeWnd(int wndType);
    void fillParam();
    void drawCADGraphic();
    std::map<QString, QString> *tableData = new std::map<QString, QString>();
    std::map<QString,QLineEdit*> *qLineMap = new std::map<QString,QLineEdit*>();
    Ui::MainWindow *ui;
    QAxObject* pAcad;

};
#endif // MAINWINDOW_H
